package com.misboot.document.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.misboot.document.mapper.OfDocumentMapper;
import com.misboot.document.model.OfDocument;
import com.misboot.document.service.OfDocumentService;
import com.misboot.document.service.impl.DocumentBaseServiceImpl;
import com.misboot.document.utils.PageUtil.PageParam;
import com.misboot.document.utils.PageUtil.PageSet;
import com.misboot.document.utils.PageUtil.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ofDocumentServiceImpl")
public class OfDocumentServiceImpl extends DocumentBaseServiceImpl<OfDocument, String> implements OfDocumentService {

    @Autowired
    private OfDocumentMapper ofDocumentMapper;

    //分页
    @Override
    public PageSet<OfDocument> getPageSet(PageParam pageParam, String filterSort) {
        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());
        List<OfDocument> list = ofDocumentMapper.getPageSet(filterSort);
        PageInfo<OfDocument> pageInfo = new PageInfo<>(list);
        return PageUtils.getPageSet(pageInfo);
    }

    //批量删除
    @Override
    public int executeDeleteBatch(String[] varchar) {
        return ofDocumentMapper.executeDeleteBatch(varchar);
    }

    //批量删除(根据id)
    @Override
    public int executeDeleteBatchByIds(String[] ids){
        return ofDocumentMapper.executeDeleteBatchByIds(ids);
    }

    //根据Pid获取数据集合
    @Override
    public List<OfDocument> getListByPid(String pid){
        return ofDocumentMapper.getListByPid(pid);
    }

    //根据Pid获取数据集合（分页）
    @Override
    public PageSet<OfDocument> getPageSetByPid(PageParam pageParam, String pid){
        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());
        List<OfDocument> list = ofDocumentMapper.getListByPid(pid);
        PageInfo<OfDocument> pageInfo = new PageInfo<>(list);
        return PageUtils.getPageSet(pageInfo);
    }

    @Override
    public Boolean getBooleanOfDocumentListByPids(String[] pid){
        Integer result = ofDocumentMapper.getComOfDocumentListByPids(pid);
        return result > 0 ? true : false ;
    }

    @Override
    public OfDocument getDataById(Integer id){
        return ofDocumentMapper.getDataById(id);
    }

    @Override
    public Integer getSubsetComtByIdAndWhetherFolder(Integer id, Integer whetherFolder){
        return ofDocumentMapper.getSubsetComtByIdAndWhetherFolder(id, whetherFolder);
    }
}
